package cn.jiadakeji.parent.service.impl;

import cn.jiadakeji.parent.common.constant.Constants;
import cn.jiadakeji.parent.common.constant.CourseStuStatusConstants;
import cn.jiadakeji.parent.domain.ClassCourseStuPlan;
import cn.jiadakeji.parent.mapper.ClassCourseStuPlanMapper;
import cn.jiadakeji.parent.service.ClassCourseStuPlanService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author heyanfeng
 * @create 2022-03-14 15:54
 */
@Service
public class ClassCourseStuPlanServiceImpl extends ServiceImpl<ClassCourseStuPlanMapper, ClassCourseStuPlan> implements ClassCourseStuPlanService {
    @Override
    public String getScheduleStatus(String id, String studentId) {
        ClassCourseStuPlan stuPlan = baseMapper.selectOne(new QueryWrapper<ClassCourseStuPlan>()
                .eq("class_course_plan_id", id)
                .eq("student_id", studentId));
        if (stuPlan != null) {
            String status = stuPlan.getScheduleStatus();
            if (Constants.STATUS_SETTING.equals(status)) {
                return CourseStuStatusConstants.SCHEDULE_ING;
            } else if ("2".equals(status)) {
                return CourseStuStatusConstants.SCHEDULE_FAILED;
            } else {
                return CourseStuStatusConstants.SCHEDULE_FINISH;
            }
        }
        return null;
    }
}
